﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Cwt;

namespace WebApp.Management.Company
{
    public partial class Update : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ICwtService service = Global.Get<ICwtService>();
                SmartSpace.Cwt.Company company = service.GetCompany();
                if (company != null)
                {
                    _ctlEditICPCode.Text = company.ICPCode;
                    _ctlEditName.Text = company.Name;
                    _ctlEditSubName.Text = company.SubName;
                    _ctlEditTelephone.Text = company.Telephone;
                    _ctlEditFax.Text = company.Fax;
                    _ctlEditEmail.Text = company.Email;
                    _ctlEditAddress.Text = company.Address;
                    _ctlEditPostCode.Text = company.PostCode;
                }
            }
        }

        protected void _ctlBtnSave_Click(object sender, EventArgs e)
        {
            ICwtService service = Global.Get<ICwtService>();
            SmartSpace.Cwt.Company company = service.GetCompany();
            if (company == null)
            {
                company = new SmartSpace.Cwt.Company();
                company.Id = Guid.NewGuid();
            }

            company.ICPCode = _ctlEditICPCode.Text;
            company.Name = _ctlEditName.Text;
            company.SubName = _ctlEditSubName.Text;
            company.Telephone = _ctlEditTelephone.Text;
            company.Fax = _ctlEditFax.Text;
            company.Email = _ctlEditEmail.Text;
            company.Address = _ctlEditAddress.Text;
            company.PostCode = _ctlEditPostCode.Text;

            if (service.SaveCompany(company))
            {
                Response.Write("<script>alert('设置成功!');window.location.reload();;</script>");
            }
            else
            {
                Response.Redirect("../Message.aspx");
            }
        }
    }
}